<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script type="text/javascript">

        function eater(){
            var food = "";

            var obj = {
                push: function(myFood) {
                    food = myFood;
                },
                eat: function() {
                    if(food != ""){
                        console.log('我正在吃' + food);
                        food = "";
                    }else{
                        console.log('弹尽粮绝');
                    }
                }
            }
            return obj;
        }
        
        var eater1 = eater();
        eater1.push('苹果');
        eater1.eat();
        eater1.eat();
    </script>
</body>
</html>